home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 247
/
247.d81
/
e.ml sub
< prev
next >
Wrap
Text File
|
2022-08-26
|
2KB
|
83 lines
u PRINT THIS
ML SUBTRACTION
--------------
LN = Large Number
SN = Smaller Number
LDA LN
LDY LN+1
SEC
SBC SN
TAX
TYA
SBC SN+1
RTS
HIGH BYTE > .A
LOW BYTE > .X
CARRY SET if POSITIVE VALUE
NOTE: If value to be subtracted
is already in .A register,
it can be subtracted from
another value this way:
(.A < SN)
EOR#255
SEC
ADC LN
The addition feature of the 6502
processor is the most complicated
function of the chip -- and a genuine
work of art. Even more clever is how
the designers made a "subtract"
feature without having to create extra
logic code.
Subtraction is, in fact, adding a
negative value to a value. In binary
math, one makes a negative value our
of a positive value by
Flipping the Bits
Adding 1
Now watch carefully. By having
only ADC and SBC instructions (which
require the programmer to Clear or Set
the Carry), not only are multi-byte
operations possible, but the
programmer provides the "Adding 1"
part of making a negative value for
subtraction.
When a value is to be subtracted
from the contents of .A, the SBC
instruction evidently does the
Flipping of the Bits as the byte
enters the processor.
.A < %00001111
SBC #%00001100
becomes: %11110011
SEC +1
---------
and ADC
00000011 w/CARRY=1
What efficiency! What Style! What
Poetry!
DMM